package com.system.web.spring;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.system.domain.T_batch_steps;
import com.system.mapper.T_batch_stepsMapper;
//import com.system.service.T_batch_stepsMapperService;

//@Service
//@Transactional
@Controller
@RequestMapping("/t_batch_steps")

public class T_batch_stepsController
{
	private static Logger log = Logger.getLogger(T_batch_stepsController.class.getName());

	//@Autowired
    //private T_batch_stepsService service;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	@Resource
	private T_batch_stepsMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_batch_steps信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_batch_steps")
	@ResponseBody
	public Pg getAllT_batch_steps(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_batch_steps t_batch_steps = new T_batch_steps();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_batch_steps.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("batchsign")!=null&&!"".equals(request.getParameter("batchsign"))){
	        	t_batch_steps.setBatchsign(request.getParameter("batchsign"));
	        }
			if(request.getParameter("batchconst")!=null&&!"".equals(request.getParameter("batchconst"))){
	        	t_batch_steps.setBatchconst(request.getParameter("batchconst"));
	        }
			if(request.getParameter("flag")!=null&&!"".equals(request.getParameter("flag"))){
	        	t_batch_steps.setFlag(request.getParameter("flag"));
	        }
			if(request.getParameter("successflag")!=null&&!"".equals(request.getParameter("successflag"))){
	        	t_batch_steps.setSuccessflag(request.getParameter("successflag"));
	        }
			if(request.getParameter("tipflag")!=null&&!"".equals(request.getParameter("tipflag"))){
	        	t_batch_steps.setTipflag(request.getParameter("tipflag"));
	        }
			if(request.getParameter("continueflag")!=null&&!"".equals(request.getParameter("continueflag"))){
	        	t_batch_steps.setContinueflag(request.getParameter("continueflag"));
	        }
			if(request.getParameter("redoflag")!=null&&!"".equals(request.getParameter("redoflag"))){
	        	t_batch_steps.setRedoflag(request.getParameter("redoflag"));
	        }
			if(request.getParameter("cye")!=null&&!"".equals(request.getParameter("cye"))){
	        	t_batch_steps.setCye(request.getParameter("cye"));
	        }
			if(request.getParameter("execflag")!=null&&!"".equals(request.getParameter("execflag"))){
	        	t_batch_steps.setExecflag(request.getParameter("execflag"));
	        }
			if(request.getParameter("calling")!=null&&!"".equals(request.getParameter("calling"))){
	        	t_batch_steps.setCalling(request.getParameter("calling"));
	        }
			if(request.getParameter("transflag")!=null&&!"".equals(request.getParameter("transflag"))){
	        	t_batch_steps.setTransflag(request.getParameter("transflag"));
	        }
      	    if(request.getParameter("batchid")!=null&&!"".equals(request.getParameter("batchid"))){
	        	t_batch_steps.setBatchid(new Integer(request.getParameter("batchid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_batch_steps.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_batch_steps.setEnddate(request.getParameter("enddate"));
	        }
	        t_batch_steps.setStartNo( startIndex );
	        t_batch_steps.setEndNo( startIndex + pageSize );
	    	List<T_batch_steps> findAll = mapper.findAll(t_batch_steps);
	        int totalCount = mapper.findCountAll(t_batch_steps);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_batch_stepsList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_batch_stepsList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_batch_steps信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_batch_steps")
	@ResponseBody
	public JsonVO saveT_batch_steps(T_batch_steps t_batch_steps, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(mapper.save(t_batch_steps)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_batch_steps信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_batch_steps
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_batch_steps")
	@ResponseBody
	public JsonVO updateT_batch_steps(T_batch_steps t_batch_steps, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_batch_steps t_batch_stepsTemp = mapper.findById(t_batch_steps);
		//t_batch_stepsTemp.setXXX(t_batch_steps.getXXX());
		//if(mapper.update(t_batch_stepsTemp)){

		if(mapper.update(t_batch_steps)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_batch_steps单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_batch_steps json格式字符串
	 */
	@RequestMapping("/getT_batch_steps")
	@ResponseBody
	public T_batch_steps getT_batch_steps(Integer id,HttpServletRequest request){
		T_batch_steps t_batch_steps = new T_batch_steps();
		t_batch_steps.setBatchid(id);
		return mapper.findById(t_batch_steps);
	}

	/**
	 * 5、删除T_batch_steps根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_batch_steps")
	@ResponseBody
	public JsonVO delT_batch_steps(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_batch_steps t_batch_steps = new T_batch_steps();
		t_batch_steps.setBatchid(id);

		if(mapper.delete(t_batch_steps)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_batch_steps/toT_batch_stepsList查询所有数据页面
	 *  return /WEB-INF/views/system/t_batch_steps/t_batch_stepsList.jsp
	 */
    @RequestMapping(value = "/toT_batch_stepsList")
    public String toT_batch_stepsList() {
    	log.debug("------跳转到/WEB-INF/views/system/t_batch_steps/t_batch_stepsList.jsp------");
        return "system/t_batch_steps/t_batch_stepsList";
    }

	/**
	 * 7、新增、修改、详情页面t_batch_steps/toT_batch_stepsCurd跳转
     * system/t_batch_steps/T_batch_stepsCurd.jsp
	 */
    @RequestMapping(value = "/toT_batch_stepsCurd")
    public String toT_batch_stepsCurd() {
    	log.debug("------跳转到/WEB-INF/views/system/t_batch_steps/t_batch_stepsCurd.jsp------");
        return "system/t_batch_steps/t_batch_stepsCurd";
    }

    /**
	 * 8、批量删除T_batch_steps根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_batch_stepsBatch")
	public String delT_batch_stepsBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_batch_steps t_batch_steps = new T_batch_steps();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_batch_steps.setBatchid(new Integer(ids[i]).intValue());
			mapper.delete(t_batch_steps);
		}
		if(j==ids.length){
			log.debug("------t_batch_steps批量删除成功！------");
		}else{
			log.error("------t_batch_steps批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_batch_steps/getAllT_batch_steps";
	}
*/



}









